package cn.edu.bcu.ls.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.edu.bcu.ls.entity.Tag;
import cn.edu.bcu.ls.entity.User;
import cn.edu.bcu.ls.serviceImpl.TagService;
import io.swagger.annotations.ApiOperation;

@RestController
public class TagController {
	
	@Autowired
	private TagService tagService;
	
	/**
	 * 增加标签
	 * @param tag
	 * @return
	 */
	@ApiOperation(value = "添加标签，传入你想要的传的值就行")
	@PostMapping(value="Tag")
	public boolean insertTag(Tag tag) {
		if (tagService.insertSelective(tag) >0) {
			return true;
		}else {
			return false;
		}
	}
	
	 @ApiOperation(value = "删除标签，传入id")
	 @DeleteMapping(value="Tag/{t_id}")
	 public boolean deleteUser(@PathVariable("t_id") Integer t_id,@PathVariable("t_name") String t_name) {
		 if (tagService.deleteByPrimaryKey(t_id,t_name) >0 ) {
				return true;
			}else {
				return false;
			}
	 }
	 
	 @ApiOperation(value="修改用户信息，传入id和想修改的值")
	 @PutMapping(value="Tag")
	 public boolean updateTag(Tag tag) {
		 if (tagService.updateByPrimaryKeySelective(tag) >0) {
				return true;
			}else {
				return false;
			}
	 }
	 @ApiOperation(value="查看标签 传入id")
	 @GetMapping(value="Tag/{t_id}")
	 public Tag queryTag(@PathVariable("t_id") Integer t_id) {
		 return tagService.selectByPrimaryKey(t_id);
		 
	 }
	
	@ApiOperation(value="查看标签 列表")
	@GetMapping(value="Tag")
	public List<Tag> queryTags(){
		return tagService.queryTag();
	}
}
